package com.ququ.syb.mqhandler.rabbitmq.handler;

import com.ququ.syb.common.constant.RabbitMqQueueNameConstant;
import com.ququ.syb.mqhandler.service.PayOrderQueryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 支付订单自动查单处理器
 * Created by Macro on 2016/8/1.
 */
@Component
public class PayOrderQueryHandler {
    private Logger logger = LoggerFactory.getLogger(PayOrderQueryHandler.class);
    @Autowired
    private PayOrderQueryService payOrderQueryService;

    @RabbitListener(containerFactory = "rabbitListenerContainerFactory",bindings=@QueueBinding(value=@Queue(RabbitMqQueueNameConstant.PAYORDER_QUERY),exchange=@Exchange("syb")))
    protected void work(Message mqmessage) {
        String message = new String(mqmessage.getBody());
        logger.debug("支付订单查询队列收到一条消息:{}",message);
        try{
            payOrderQueryService.queryPayOrder(message);
        }catch (Exception e){
            logger.error("消息队列处理异常:{};{}",message,e);
        }
    }
}
